<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page
	import="java.util.ArrayList"
 %>

<%
	String code = "1691001020600";//条形码内容
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>barcode</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
.imag {
	border-top-width: 1px;
	border-right-width: 1px;
	border-bottom-width: 1px;
	border-left-width: 1px;
	border-top-style: none;
	border-right-style: solid;
	border-bottom-style: solid;
	border-left-style: none;
	border-top-color: #000000;
	border-right-color: #000000;
	border-bottom-color: #000000;
	border-left-color: #000000;
	height: 260px;
	width: 510px;

}

-->
</style>
<script language="javascript">
<!--
NS4 = (document.layers) ? 1 : 0;
visble_property_prefix = (NS4) ? "document.layers." : "";
visble_property_suffix = (NS4) ? ".visibility" : ".style.display";
visble_property_true = (NS4) ? "show" : "block";
visble_property_false = (NS4) ? "hide" : "none";
visble_property_printview = visble_property_prefix + "viewpanel" + visble_property_suffix;
function nowprint() {
	window.print();
}
function window.onbeforeprint() {
	eval(visble_property_printview + " = \"" + visble_property_false + "\"");
}
function window.onafterprint() {
	eval(visble_property_printview + " = \"" + visble_property_true + "\"");
}
//-->
</script>
</head>
<body topmargin="0px" leftmargin="0px" rightmargin="0px" bottommargin="0px">

<%
	String ls_stext ="";
    int li_sl=0;
    int li_rc=0;
    long li_tmp=0;
    int i=0;
    int j=0;
    int k=0;
    String EAN13="";
    String tableA="";
    int li_first=0;
    String CodeBarre="";
    String chaine="";
    StringBuffer barCode;
    ArrayList al = new ArrayList();
    int checksum=0;
    ls_stext = request.getParameter("stext").toLowerCase();
    li_sl = Integer.parseInt(request.getParameter("sl"));
    if (li_sl > 0){

        for(li_rc=0;li_rc<li_sl;li_rc++){
           checksum=0;
           k=0;
           code = ls_stext;
           li_tmp = Long.parseLong(code);
           li_tmp = li_tmp + li_rc;
           code= li_tmp + "";
           chaine = code;
            //And they are really digits
            for (i = 1; i < 13; i++) {
                j = (int)(chaine.substring(i - 1, i )).charAt(0);
                if (j < 48 || j > 57) {
                    i = 0;
                    break;
                }
            }
            if (i == 13) {
                //Invalid_string_refer_to_original_code
                //Calculation of the checksum
                for (i = 12; i > 0; i = i - 2) {

                    checksum = checksum + Integer.parseInt(chaine.substring(i - 1  , i));
                }
                checksum = checksum * 3;
                for (i = 11; i > 0; i = i - 2) {

                    checksum = checksum + Integer.parseInt(chaine.substring(i - 1  , i ));
                }
                //The li_first digit is taken just as it is, the second one come from table A
                k = (10 - checksum%10)%10;
                chaine = chaine + k;
                EAN13=chaine;
                /*
                CodeBarre = chaine.substring(1,1) + (char)(65 + Integer.parseInt(chaine.substring(1, 2)));

                li_first = Integer.parseInt(chaine.substring(0, 1));
                for (i = 3; i < 8; i++) {
                    tableA = "False" ;
                    switch (i) {
                        case 3:
                            if( li_first==0 || li_first==1 || li_first==2 || li_first==3){
                               tableA = "True";
                            }
                            break;
                        case 4:
                            if( li_first==0 || li_first==4 || li_first==7 || li_first==8){
                               tableA = "True";
                            }
                        case 5:
                            if( li_first==0 || li_first==1 || li_first==4 || li_first==5 || li_first==9){
                               tableA = "True";
                            }
                        case 6:
                            if( li_first==0 || li_first==2 || li_first==5 || li_first==6 || li_first==7){
                               tableA = "True";
                            }
                        case 7:
                            if( li_first==0 || li_first==3 || li_first==6 || li_first==8 || li_first==9){
                                tableA = "True";
                            }
                    }
                if (tableA.equalsIgnoreCase("true"))  {
                    CodeBarre = CodeBarre + (char)(65 + Integer.parseInt(chaine.substring(i - 1, i )));
                } else {
                    CodeBarre = CodeBarre + (char)(75 + Integer.parseInt(chaine.substring(i - 1, i )));
                }
            }
            CodeBarre = CodeBarre + "*"; // Add middle separator
            for (i = 8; i < 14; i++) {
                CodeBarre = CodeBarre + (char)(97 + Integer.parseInt(chaine.substring(i - 1, i )));
            }
            CodeBarre = CodeBarre + "+"; // Add end mark
            EAN13 = CodeBarre;
            */
        }
        al.add(EAN13);
       }
       for(i=0;i<al.size();i++){
       code = al.get(i).toString();
       barCode = new StringBuffer();
       barCode.append("<div class='imag'>");
       barCode.append("<img src='./barcode/");
       barCode.append(code);
       barCode.append(".jpg' width='504' height='252' > ");
       barCode.append("</div>");
       out.println(barCode.toString());
       //cls
       code="";
       }

    }
%>

<div id="viewpanel" align="center">
    <br />
    <br />

<input name="bequery" type="button" value="打  印" style="cursor:hand;" onclick="nowprint();">
</div>
<!--script>nowprint();</script-->
</body>
</html>